package com.itheima.UDPdemo.练习;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.util.Scanner;

public class SendMessageDemo {
    public static void main(String[] args) throws IOException {
        //一直发消息
        DatagramSocket ds=new DatagramSocket();//快递公司不需要一直创建

        while (true) {
            Scanner scanner=new Scanner(System.in);
            System.out.println("输入您要说的话");
            String test= scanner.next();
            if("886".equals(test)){//知道说的话是886，就结束
                break;
            }
            byte[] bytes=test.getBytes();

            InetAddress inetAddress=InetAddress.getByName("127.0.0.1");

            int port=10086;

            DatagramPacket dp=new DatagramPacket(bytes,bytes.length,inetAddress,port);

            ds.send(dp);
        }

        ds.close();
    }
}
